<template>
  <el-dialog v-model="dialog.visible" title="查看详情" width="40%" @close="handleCloseDialog">
    <el-descriptions
      class="margin-top h-[600px] overflow-y-auto"
      title=""
      :column="2"
      border
      label-width="150"
    >
      <el-descriptions-item label="业主名称">
        {{ formData.commissionExt.ownName }}
      </el-descriptions-item>
      <el-descriptions-item label="房屋信息">
        {{ `${formData.commissionExt?.region}${formData.commissionExt?.houseNumber}` }}
      </el-descriptions-item>
      <el-descriptions-item label="佣金积分">{{ formData.commissionCoins || 0 }}</el-descriptions-item>
      <el-descriptions-item label="合同金额">
        {{ formData.contractAmount || 0 }}
      </el-descriptions-item>
      <el-descriptions-item label="签约合同">
        <image-preview
          v-for="(item, index) in JSON.parse(formData.contractFile || '[]')"
          :key="index"
          width="100px"
          height="100px"
          :src="item.url"
        ></image-preview>
      </el-descriptions-item>
      <el-descriptions-item label="品类">{{ formData.categoryText || "" }}</el-descriptions-item>
      <el-descriptions-item label="签约时间">{{ formData.contractTime }}</el-descriptions-item>
      <el-descriptions-item label="状态">
        <el-tag :type="COMMISSION_STATUS_MAP[formData.commissionStatus] || 'info'">
          {{ getLabelByValue(COMMISSION_STATUS_ENUM, formData.commissionStatus) }}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="是否逾期">
        <el-tag :type="IS_OVERDUE_MAP[formData.isOverdue] || 'info'">
          {{ getLabelByValue(IS_OVERDUE_ENUM, formData.isOverdue) }}
        </el-tag>
      </el-descriptions-item>
    </el-descriptions>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleCloseDialog">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup lang="ts">
// 定义 emit，用于通知外部关闭事件
import ImagePreview from "@/components/ImagePreview/index.vue";
import {
  COMMISSION_STATUS_ENUM,
  COMMISSION_STATUS_MAP,
  IS_OVERDUE_ENUM,
  IS_OVERDUE_MAP,
} from "@/enums/commission/commissionEnum";
import { getLabelByValue } from "@/utils/enums";

const emit = defineEmits(["update:modelValue", "loadData"]);

const dialog = reactive({
  title: "",
  visible: false,
});
const defaultFormData = {};
const formData = ref({
  ...defaultFormData,
});

async function handleSubmit() {}

// 关闭弹窗
function handleCloseDialog() {
  dialog.visible = false;
  Object.assign(formData.value, defaultFormData);
  emit("update:modelValue", false); // 关闭弹窗
}

function showModal(val) {
  dialog.visible = true;
  formData.value = val;
}
defineExpose({
  showModal,
});
</script>
<style style="scss" scoped>
::v-deep(.el-tabs__content) {
  min-height: 100px;
  display: flex;
  align-items: center;
}
</style>
